package com.jbob.app;

import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.HeadlessException;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.dial.DialBackground;
import org.jfree.chart.plot.dial.DialCap;
import org.jfree.chart.plot.dial.DialPlot;
import org.jfree.chart.plot.dial.DialPointer;
import org.jfree.chart.plot.dial.DialTextAnnotation;
import org.jfree.chart.plot.dial.DialValueIndicator;
import org.jfree.chart.plot.dial.StandardDialFrame;
import org.jfree.chart.plot.dial.StandardDialRange;
import org.jfree.chart.plot.dial.StandardDialScale;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.GradientPaintTransformType;
import org.jfree.ui.StandardGradientPaintTransformer;


public class ResultWindow extends JFrame
{
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	
	double precision1 = 0.0;
	double precision2 = 0.0;
	
	public ResultWindow(double precisionNaive, double precisionJ48) throws HeadlessException 
	{
		super();
		precision1 = precisionNaive;
		precision2 = precisionJ48;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(700, 880);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		contentPane = new JPanel();
		
		//JFreeChart chart = createChart();
		DialPlot plot1 = new DialPlot();
		DialPlot plot2 = new DialPlot();
	    DefaultValueDataset data = new DefaultValueDataset(0.0);
	    StandardDialFrame frame = new StandardDialFrame();
	    
	    frame.setForegroundPaint(Color.darkGray);
	    GradientPaint paint = new GradientPaint(new Point(), new Color(255,255,255), new Point(), new Color(154,204,255));
	    DialBackground db = new DialBackground(paint);
        db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
	    frame.setBackgroundPaint(paint);
	    plot1.setDialFrame(frame);
	    plot2.setDialFrame(frame);
	    DialTextAnnotation annotation1 = new DialTextAnnotation("Pourcentages");
        annotation1.setFont(new Font("Dialog", Font.BOLD, 14));
        annotation1.setRadius(0.7);
        plot1.addLayer(annotation1);
        plot2.addLayer(annotation1); 
        DialValueIndicator dvi = new DialValueIndicator();
        plot1.addLayer(dvi);
        plot2.addLayer(dvi);
        
        StandardDialScale scale = new StandardDialScale(0, 100, -120, -300, 10, 1);
        scale.setTickRadius(0.88);
        scale.setTickLabelOffset(0.15);
        scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 14));
        plot1.addScale(0, scale);
        plot2.addScale(0, scale);
        
        StandardDialRange range = new StandardDialRange(0.0, 50.0, Color.red);
        range.setInnerRadius(0.52);
        range.setOuterRadius(0.58);
        plot1.addLayer(range);
        plot2.addLayer(range);
        StandardDialRange range2 = new StandardDialRange(50.0, 70.0, Color.yellow);
        range2.setInnerRadius(0.52);
        range2.setOuterRadius(0.58);
        plot1.addLayer(range2);
        plot2.addLayer(range2);
        StandardDialRange range3 = new StandardDialRange(70.0, 100.0, Color.green);
        range3.setInnerRadius(0.52);
        range3.setOuterRadius(0.58);
        plot1.addLayer(range3);
        plot2.addLayer(range3);
        
        DialPointer needle = new DialPointer.Pointer();
        plot1.addLayer(needle);
        plot2.addLayer(needle);
        DialCap cap = new DialCap();
        cap.setRadius(0.1);
        plot1.setCap(cap);
        plot2.setCap(cap);
	    
	    JFreeChart chart1 = new JFreeChart("NAIVES BAYES",
	    JFreeChart.DEFAULT_TITLE_FONT, plot1, false);
	    plot1.setNoDataMessage("Pas de valeur");

	    JFreeChart chart2 = new JFreeChart("J48",
	    JFreeChart.DEFAULT_TITLE_FONT, plot2, false);
	    plot2.setNoDataMessage("Pas de valeur");
	    
		contentPane.add(new ChartPanel(chart1));
		contentPane.add(new ChartPanel(chart2));
		
		// Utilisation des valeurs de précision récupérées.
		DefaultValueDataset data1 = new DefaultValueDataset(precision1);
		DefaultValueDataset data2 = new DefaultValueDataset(precision2);
		
		plot1.setDataset(data1);
		plot2.setDataset(data2);
	    	    
		this.setContentPane(contentPane);
		this.setTitle("Resultats");
		this.setVisible(true);
	}
}
